package com.ruoyi.ex.domain;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.pv.domain.PvUserInfo;
import lombok.*;

import java.util.Date;
import java.util.List;

/**
 * 考试报名记录对象 ex_study_reload
 *
 * @author zzx
 * @date 2023-05-06
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@ToString
public class ExStudyReloadExcel {

    @Excel(name = "用户")
    private String userName;

    @Excel(name = "社区")
    private String community;

    @Excel(name = "手机号码")
    private String phonenumber;

    @Excel(name = "考试")
    private String bankName;

    @Excel(name = "考试日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date exDate;

    @Excel(name = "考试时间范围")
    private String exTime;

    @Excel(name = "对题数")
    private Integer right;

    @Excel(name = "得分")
    private Double score;

    @Excel(name = "状态",dictType = "ex_study_reload_status")
    private Integer status;

    public ExStudyReloadExcel(ExStudyReload reload) {
        SysUser user = reload.getUser();
        PvUserInfo userInfo = user.getUserInfo(PvUserInfo.class);
        this.userName = user.getNickName();
        this.phonenumber = user.getPhonenumber();
        this.community = userInfo.getCommunity();
        this.bankName = reload.getBankName();
        this.exDate = reload.getExDate();
        JSONObject exTimeObj = reload.getExTimeObj();
        List<String> times = exTimeObj.getBeanList("time", String.class);
        this.exTime = StrUtil.format("【{}】{}~{}",exTimeObj.getStr("name"),times.get(0),times.get(1));
        this.right = reload.getRight();
        this.score = reload.getScore();
        this.status = reload.getStatus();
    }
}
